//
//  TWFXShowWeatherViewController.m
//  TWFXWeather
//
//  Created by Lion User on 13-10-14.
//  Copyright (c) 2013年 Lion User. All rights reserved.
//

#import "TWFXCityCurrentWeatherViewController.h"

@interface TWFXCityCurrentWeatherViewController ()

@end

@implementation TWFXCityCurrentWeatherViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    
    //获取屏幕的高度(不含状态栏)
    CGFloat heightOfScreen = [UIScreen mainScreen].applicationFrame.size.height;
    
    //view 的坐标远点及高宽
    CGFloat heightOfView = heightOfScreen - 44 - 49 - 20 - 20;


    self.outlet_realtime = [[[UILabel alloc] initWithFrame:CGRectMake(170, 10, 130, 85)] autorelease];//靠近view的右边
    self.outlet_aqi = [[[UILabel alloc] initWithFrame:CGRectMake(195, 100, 80, 60)] autorelease];
    
    self.outlet_realtime.BackgroundColor = [UIColor clearColor];
    self.outlet_aqi.BackgroundColor = [UIColor clearColor];
    
    self.outlet_realtime.font = [UIFont systemFontOfSize:66];
    self.outlet_realtime.textColor = [UIColor whiteColor];
    self.outlet_realtime.textAlignment = NSTextAlignmentCenter;
    
    self.outlet_aqi.font = [UIFont systemFontOfSize:20];
    self.outlet_aqi.textColor = [UIColor whiteColor];
    self.outlet_aqi.numberOfLines = 0;
    [self.outlet_aqi setTextAlignment:NSTextAlignmentCenter];
    
    UILabel *line = [[UILabel alloc] initWithFrame:CGRectMake(170, 90, 120, 5)];
    line.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
    [self.view addSubview:line];
    [line release];
    
    [self.view addSubview:self.outlet_realtime];
    [self.view addSubview:self.outlet_aqi];

    self.view.backgroundColor = [UIColor clearColor];
    
    
    
    //靠近view的底部
    UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, heightOfView - 90, 300, 90)];
    tempView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.16];
    
    self.outlet_weather = [[[UILabel alloc] initWithFrame:CGRectMake(20, 5, 200, 30)] autorelease];
    self.outlet_fengli = [[[UILabel alloc] initWithFrame:CGRectMake(20, 35, 200, 25)] autorelease];
    self.outlet_time = [[[UILabel alloc] initWithFrame:CGRectMake(20, 60, 200, 20)] autorelease];
    
    
    self.outlet_weather.font = [UIFont systemFontOfSize:22];
    self.outlet_weather.textColor = [UIColor whiteColor];
    self.outlet_weather.textAlignment = NSTextAlignmentLeft;
        
    self.outlet_fengli.font = [UIFont systemFontOfSize:17];
    self.outlet_fengli.textColor = [UIColor whiteColor];
    self.outlet_fengli.textAlignment = NSTextAlignmentLeft;
    
    self.outlet_time.font = [UIFont systemFontOfSize:14];
    self.outlet_time.textColor = [UIColor whiteColor];
    self.outlet_time.textAlignment = NSTextAlignmentLeft;
    
    self.outlet_weather.backgroundColor = [UIColor clearColor];
    self.outlet_fengli.backgroundColor = [UIColor clearColor];
    self.outlet_time.backgroundColor = [UIColor clearColor];
    
    
    [tempView addSubview:self.outlet_weather];
    [tempView addSubview:self.outlet_fengli];
    [tempView addSubview:self.outlet_time];
    
    [self.view addSubview:tempView];
    

    [tempView release];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)dealloc
{
    
    [_outlet_aqi release];
    [_outlet_realtime release];
    
    [super dealloc];
}


- (void)refreshUI:(TWFXStruct_AllWeatherInfo *)weatherInfo
{

    
    TWFXStruct_RealTimeWeatherInfo *realTime = weatherInfo.realTimeWeatherInfo;
    TWFXStruct_FutureWeatherInfo *future = weatherInfo.futureWeatherInfo;
    TWFXStruct_AQIInfo *AQIInfo = weatherInfo.AQIInfo;

    
    if (realTime.temp != nil)
    {
        self.outlet_realtime.font = [UIFont systemFontOfSize:66];
        NSString *str_realTime = [NSString stringWithFormat:@"%@°",realTime.temp];
        self.outlet_realtime.text = str_realTime;
    }
    else
    {
        self.outlet_realtime.font = [UIFont systemFontOfSize:30];
        self.outlet_realtime.text = @"未同步";
    }
    
 //   NSString *str_future;
    if (future.img_title1 != nil)
    {
       // self.showView.hidden = NO;
        self.outlet_weather.text = future.img_title1;
        self.outlet_fengli.text = [NSString stringWithFormat:@"%@%@", realTime.WD, realTime.WS];
        
        NSString* str = future.date_y;
        str = [str stringByReplacingOccurrencesOfString:@"年" withString:@"-"];
        str = [str stringByReplacingOccurrencesOfString:@"月" withString:@"-"];
        str = [str stringByReplacingOccurrencesOfString:@"日" withString:@""];
        
        self.outlet_time.text = [NSString stringWithFormat:@"%@ %@ 发布",str, realTime.time];
    }
    else
    {
        self.showView.backgroundColor = [UIColor clearColor];
    }
    
    
    if (AQIInfo.aqi != nil) {
        
        NSString *str_Aqi = [NSString stringWithFormat:@"AQI: %@ %@",AQIInfo.aqi,AQIInfo.quality];
        
        self.outlet_aqi.text = str_Aqi;
    }
    else
    {
        self.outlet_aqi.text = @"";
    }
    
}




@end




















